﻿/*-----------------------------------------------
// File: BCEntranceState.cs 
// Description: 渲染层，英雄对象入场状态，战斗刚开始或怪物波次刷新时，未入场的对象会进入入场状态 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;

namespace Battle.View
{
    public class BCEntranceState : Fsm.FsmStateMonoBase<ActorState> 
    {
        BattleCharacter bc {
            get { return this.controller as BattleCharacter; }
        }
        public BCEntranceState(ActorState state, BattleCharacter ctrl) : base(state, ctrl) {
        }

        Vector3 fromPos;
        Vector3 endPos;

        public override void Enter()
        {
            if (bc.camp == BattleCamp.Defender)
            {
                bc.transform.localPosition = bc.GetStandPosition();
                bc.transform.localEulerAngles = bc.GetStandEulerAngle();
                isEntranceOver = true;
                bc.PlayStand(true);
            }
            else {
                fromPos = bc.GetEntranceStandPosition();
                endPos = bc.GetStandPosition();
                bc.transform.localPosition = fromPos;
                isEntranceOver = false;
                bc.PlayRun();
                //bc.PlayJumpForward();
            }
        }

        public bool isEntranceOver = false;
        public const float entranceSpeed = 10f;

        public override void Update()
        {
            if (!isEntranceOver)
            {
                bc.transform.Translate(Vector3.forward * entranceSpeed * Time.deltaTime);
                if (Vector3.Distance(bc.transform.localPosition, endPos) <= entranceSpeed * Time.deltaTime)
                {
                    bc.transform.localPosition = endPos;
                    bc.transform.localEulerAngles = bc.GetStandEulerAngle();
                    isEntranceOver = true;
                    bc.PlayStand();
                }
            }
        }
    }
}
